/*
 * time_dialog.cpp
 *
 *  Created on: 15.07.2013
 *      Author: SpirTanol
 */

#include "ui/time_dialog.h"

// QT
#include <QDateTimeEdit>
#include <QPushButton>
#include <QGridLayout>

TimeDialog::TimeDialog(uint time)
{
	setWindowTitle(trUtf8("Время"));

	setFixedSize(200, 105);

	int row = 0;

	QGridLayout *l = new QGridLayout(this);

	oDateTimeEdit = new QDateTimeEdit(QDateTime::fromTime_t(time));
	oDateTimeEdit->setDisplayFormat("dd.MM.yyyy hh:mm:ss");
	//oDateTimeEdit->setTimeSpec(Qt::UTC);
	l->addWidget(oDateTimeEdit, row++, 0, 1, 2);

	QPushButton *btn;
	btn = new QPushButton(trUtf8("Синхронизировать"));
	l->addWidget(btn, row++, 0, 1, 2);
	connect(btn, SIGNAL(clicked()), this, SLOT(syncTime()));

	btn = new QPushButton(trUtf8("Ок"));
	l->addWidget(btn, row, 0, 1, 1);
	connect(btn, SIGNAL(clicked()), this, SLOT(accept()));

	btn = new QPushButton(trUtf8("Отмена"));
	l->addWidget(btn, row, 1, 1, 1);
	connect(btn, SIGNAL(clicked()), this, SLOT(reject()));
}

TimeDialog::~TimeDialog()
{

}

uint TimeDialog::time() const
{
	return oDateTimeEdit->dateTime().toTime_t();
}

void TimeDialog::syncTime()
{
	oDateTimeEdit->setDateTime(QDateTime::currentDateTime());
}
